<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.condition.account"
        placeholder="名称"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />

      <el-select
        v-model="listQuery.condition.user_status"
        placeholder="状态"
        clearable
        class="filter-item"
        style="width: 130px"
      >

        <el-option
          v-for="item in UserStatusOptions"
          :key="item.key"
          :label="item.display_name"
          :value="item.id"
        />
      </el-select>
      <el-select
        v-model="listQuery.condition.account_type"
        placeholder="账号类型"
        style="width: 140px"
        class="filter-item"
        @change="handleFilter"
      >

        <el-option
          v-for="item in AccountTypeOptions"
          :key="item.key"
          :label="item.display_name"
          :value="item.id"
        />
      </el-select>

      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        class="filter-item"
        style="margin-left: 10px"
        type="primary"
        icon="el-icon-edit"
        @click="handleCreate"
        v-purview-check="{
          modules: 'sys_account',
          resources: 'sys_account',
          operates: 'add',
        }"
      >
        添加
      </el-button>
    </div>

    <el-row :gutter="20">
      <el-col :span="3"
        ><div class="grid-content bg-purple">
          <el-tree
            :data="tree_data"
            node-key="id"
            :default-expand-all="true"
            :default-checked-keys="defaultselectKey"
            :props="defaultProps"
            @node-click="handleNodeClick"
          >
          </el-tree></div
      ></el-col>
      <el-col :span="21">
        <div class="grid-content bg-purple">
          <el-table
            :data="BaseDataList"
            style="width: 100%; margin-top: 30px"
            border
          >
            <!-- <el-table-column align="center" label="ID" width="220">
              <template slot-scope="scope">
                {{ scope.row.id }}
              </template>
            </el-table-column> -->
            <el-table-column align="center" label="账号" width="150">
              <template slot-scope="scope">
                {{ scope.row.account }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="别名" width="150">
              <template slot-scope="scope">
                {{ scope.row.alias_name }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="名称">
              <template slot-scope="scope">
                {{ scope.row.chr_name }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="邮箱">
              <template slot-scope="scope">
                {{ scope.row.email }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="联系电话">
              <template slot-scope="scope">
                {{ scope.row.mobile_phone }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="最后登录时间">
              <template slot-scope="scope">
                {{ scope.row.last_login_time }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="最后登录IP">
              <template slot-scope="scope">
                {{ scope.row.last_login_ip }}
              </template>
            </el-table-column>

            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="small"
                  @click="handleEdit(scope)"
                  v-purview-check="{
                    modules: 'sys_account',
                    resources: 'sys_account',
                    operates: 'modify',
                  }"
                >
                  修改
                </el-button>
                <el-button
                  type="danger"
                  size="small"
                  @click="handleDelete(scope)"
                  v-purview-check="{
                    modules: 'sys_account',
                    resources: 'sys_account',
                    operates: 'delete',
                  }"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="listQuery.page_index"
            :limit.sync="listQuery.page_size"
            @pagination="getList"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { BaseDataTypeList, BaseDataList } from "@/api/basedata";
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Constants from "@/utils/constants";
import { GetAccountList } from "@/api/account";
export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      UserStatusOptions: [],
      AccountTypeOptions: [],
      total: 0,
      defaultselectKey: [-1],
      listQuery: {
        page_size: 20,
        page_index: 1,
        condition: {
          account: "",
          user_status: "",
          mobile_phone: "",
          account_type: "",
        },
      },
      tree_data: [
        {
          id: -1,
          display_name: "全部账号",
          children: [
            
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "display_name",
      },

      downloadLoading: false,
      BaseDataList:[]
    };
  },
  methods: {
    handleNodeClick(data) {
      this.BaseDataList = [];
      this.listQuery.condition.account_type = data.id;
      this.total = 0;
      this.listQuery.page_index = 1;
      this.getList();
    },
    getList() {
      GetAccountList(this.listQuery).then((res) => {
        this.BaseDataList = res.data.list;
        this.total = res.data.total;
      });
    },
    handleFilter() {
      this.BaseDataList = [];
      this.total = 0;
      this.listQuery.page_index = 1;
      this.getList();
    },
    handleCreate() {},
    handleDownload() {},
    handleEdit() {},
    handleDelete() {},
  },
  mounted() {
    this.getList();
    this.tree_data[0].children.push(...Constants.account_type)
    this.UserStatusOptions = Constants.user_status;
    this.AccountTypeOptions = Constants.account_type;
  },
};
</script>
<style scoped>
</style>
